﻿'use strict';

// todoPage controller
app.controller('allSelect', ['$state','$filter','$window','$http','$scope','$modal','toaster','$log', function($state,$filter,$window,$http,$scope,$modal,toaster,$log) {

    $scope.saveDate={};
    $scope.title = {
        addTitle:'枚举信息维护'
    };
    $scope.toaster = {
        type: 'warning',
        title: '提示：',
        text: '内容不能为空！'
    };
    function getList(){
        toaster.getInfo('/a_yongan/list/allselect',null).then(function(data){
            if(data && data.data && data.data.data){
                $scope.saveDate=data.data.data;
            }
        });
    }
    getList();
    $scope.pop = function(){
        toaster.pop($scope.toaster.type, $scope.toaster.title, $scope.toaster.text);
    };
    function showMessage(type,title,text){
        $scope.toaster.type = type;
        $scope.toaster.text = text;
        toaster.pop($scope.toaster.type, $scope.toaster.title, $scope.toaster.text);
    }
    function checkItems(){
        var items = ['allSelectDwxz','allSelectCklx','allSelectRklx','allSelectChuklx','allSelectJsfs'];
        var itemsValue = ['单位性质','仓库类型','入库类型','出库类型','结算方式'];
        for(var i=0;i<items.length;i++){
            if($('#'+items[i]+'').val()===''){
                $('#'+items[i]+'').focus();
                showMessage('warning','',itemsValue[i]+"不能为空！");
                return false;
            }
        }
        return true;
    }
    $scope.message = '是否确定保存？';
    $scope.saveInfo = function (size) {
        if(!checkItems()){
            return;
        }
        var modalInstance = $modal.open({
            templateUrl: 'myModalContent.html',
            controller: 'ModalInstanceCtrl',
            size: size,
            resolve: {
                items: function () {
                    return $scope.message;
                }
            }
        });
        modalInstance.result.then(function (selectedItem) {
            addDo();
        }, function () {
            $log.info('Modal dismissed at: ' + new Date());
        });
    };
    function addDo(){
        toaster.postInfo('/a_yongan/add/allselect',$scope.saveDate).then(function(data){
            if(data && data.data && data.data.success){
                showMessage('seccess','','保存成功！');
            }else{
                showMessage('warning','',"保存失败！");
            }
        });
    }
}])
;